library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
dataGI <- as.data.frame(read_excel("~/GitHub/LatentBiomarkers/Data/GI/data.xlsx", sheet = "Sheet1"))
dataGI$ID <- NULL
table(dataGI$V2)
#>
#> 1 2
#> 76 76
dataSet1 <- subset(dataGI,V2==1)
class <- dataSet1$V1
dataSet1$V1 <- NULL
dataSet1$V2 <- NULL
colnames(dataSet1) <- paste(colnames(dataSet1),"WL",sep="_")
dataSet2 <- subset(dataGI,V2==2)
dataSet2$V1 <- NULL
dataSet2$V2 <- NULL
colnames(dataSet2) <- paste(colnames(dataSet2),"NBI",sep="_")
dataGI <- cbind(dataSet1,dataSet2)
dataGI$class <- 1*(class > 1)
table(dataGI$class)
#>
#> 0 1
#> 21 55
studyName <- "GI"
dataframe <- dataGI
outcome <- "class"
TopVariables <- 10
thro <- 0.80
cexheat = 0.15
Some libraries
library(psych)
library(whitening)
library("vioplot")
library("rpart")
pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
| rows | col |
|---|---|
| 76 | 1396 |
pander::pander(table(dataframe[,outcome]))
| 0 | 1 |
|---|---|
| 21 | 55 |
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
largeSet <- length(varlist) > 1500
Scaling and removing near zero variance columns and highly co-linear(r>0.99999) columns
### Some global cleaning
sdiszero <- apply(dataframe,2,sd) > 1.0e-16
dataframe <- dataframe[,sdiszero]
varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
dataframe <- dataframe[,tokeep]
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples
dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData
numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000
if (!largeSet)
{
hm <- heatMaps(data=dataframeScaled[1:numsub,],
Outcome=outcome,
Scale=TRUE,
hCluster = "row",
xlab="Feature",
ylab="Sample",
srtCol=45,
srtRow=45,
cexCol=cexheat,
cexRow=cexheat
)
par(op)
}
The heat map of the data
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
#cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
cormat <- cor(dataframe[,varlist],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Original Correlation",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.9999797
DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#>
#> V644_WL V599_WL V198_NBI V497_NBI V497_WL V260_NBI
#> V3_WL V4_WL V5_WL V6_WL V7_WL V8_WL
#> 0.7462069 0.6082759 0.5172414 0.5158621 0.5365517 0.5310345
#>
#> Included: 725 , Uni p: 0.0002068966 , Base Size: 125 , Rcrit: 0.3949911
#>
#>
1 <R=1.000,thr=0.950>, Top: 69< 48 >[Fa= 69 ]( 69 , 178 , 0 ),<|>Tot Used: 247 , Added: 178 , Zero Std: 0 , Max Cor: 1.000
#>
2 <R=1.000,thr=0.950>, Top: 15< 25 >[Fa= 84 ]( 15 , 88 , 69 ),<|>Tot Used: 308 , Added: 88 , Zero Std: 0 , Max Cor: 0.999
#>
3 <R=0.999,thr=0.950>, Top: 12< 5 >[Fa= 94 ]( 10 , 40 , 84 ),<|>Tot Used: 318 , Added: 40 , Zero Std: 0 , Max Cor: 0.989
#>
4 <R=0.989,thr=0.950>, Top: 4< 2 >[Fa= 98 ]( 4 , 7 , 94 ),<|>Tot Used: 321 , Added: 7 , Zero Std: 0 , Max Cor: 0.950
#>
5 <R=0.950,thr=0.900>, Top: 92< 1 >[Fa= 147 ]( 88 , 148 , 98 ),<|>Tot Used: 469 , Added: 148 , Zero Std: 0 , Max Cor: 0.949
#>
6 <R=0.949,thr=0.900>, Top: 16< 1 >[Fa= 154 ]( 16 , 17 , 147 ),<|>Tot Used: 487 , Added: 17 , Zero Std: 0 , Max Cor: 0.907
#>
7 <R=0.907,thr=0.900>, Top: 1< 1 >[Fa= 155 ]( 1 , 1 , 154 ),<|>Tot Used: 489 , Added: 1 , Zero Std: 0 , Max Cor: 0.900
#>
8 <R=0.900,thr=0.800>, Top: 98< 1 >[Fa= 195 ]( 92 , 152 , 155 ),<|>Tot Used: 572 , Added: 152 , Zero Std: 0 , Max Cor: 0.926
#>
9 <R=0.926,thr=0.900>, Top: 1< 1 >[Fa= 196 ]( 1 , 1 , 195 ),<|>Tot Used: 573 , Added: 1 , Zero Std: 0 , Max Cor: 0.897
#>
10 <R=0.897,thr=0.800>, Top: 31< 1 >[Fa= 206 ]( 27 , 38 , 196 ),<|>Tot Used: 600 , Added: 38 , Zero Std: 0 , Max Cor: 0.894
#>
11 <R=0.894,thr=0.800>, Top: 8< 2 >[Fa= 211 ]( 7 , 11 , 206 ),<|>Tot Used: 612 , Added: 11 , Zero Std: 0 , Max Cor: 0.884
#>
12 <R=0.884,thr=0.800>, Top: 7< 1 >[Fa= 214 ]( 4 , 5 , 211 ),<|>Tot Used: 619 , Added: 5 , Zero Std: 0 , Max Cor: 0.884
#>
13 <R=0.884,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.884
#>
14 <R=0.884,thr=0.800>, Top: 4< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.881
#>
15 <R=0.881,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.868
#>
16 <R=0.868,thr=0.800>, Top: 4< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.814
#>
17 <R=0.814,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.799
#>
18 <R=0.799,thr=0.800>
#>
[ 18 ], 0.7993308 Decor Dimension: 619 Nused: 619 . Cor to Base: 363 , ABase: 725 , Outcome Base: 0
#>
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]
pander::pander(sum(apply(dataframe[,varlist],2,var)))
7.73e+08
pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))
1.55e+08
pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))
0.306
pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))
0.212
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
UPLTM <- attr(DEdataframe,"UPLTM")
gplots::heatmap.2(1.0*(abs(UPLTM)>0),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
}
Displaying the features associations
par(op)
if (ncol(dataframe) < 1000)
{
DEdataframeB <- ILAA(dataframe,verbose=TRUE,thr=thro,bootstrap=30)
transform <- 1*(attr(DEdataframeB,"UPLTM") != 0)
print(ncol(transform))
thrcol <- 1 + 0.025*nrow(transform)
rsum <- apply(1*(transform !=0),1,sum) > 2
csum <- apply(1*(transform !=0),2,sum) > thrcol | rsum
transform <- transform[csum,csum]
csum <- (apply(1*(transform !=0),2,sum) > 1) & (apply(1*(transform !=0),1,sum) > 1)
transform <- transform[csum,csum]
print(ncol(transform))
if (ncol(transform)>100)
{
thrcol <- 1 + 0.10*nrow(transform)
rsum <- apply(1*(transform !=0),1,sum) > 4
csum <- apply(1*(transform !=0),2,sum) > thrcol | rsum
transform <- transform[csum,csum]
csum <- (apply(1*(transform !=0),2,sum) > 3) & (apply(1*(transform !=0),1,sum) > 3)
transform <- transform[csum,csum]
}
print(ncol(transform))
if (ncol(transform)>100)
{
thrcol <- 1 + 0.20*nrow(transform)
rsum <- apply(1*(transform !=0),1,sum) > 8
csum <- apply(1*(transform !=0),2,sum) > thrcol | rsum
transform <- transform[csum,csum]
csum <- (apply(1*(transform !=0),2,sum) > 7) & (apply(1*(transform !=0),1,sum) > 7)
transform <- transform[csum,csum]
}
print(ncol(transform))
if ((ncol(transform) > 10) && (ncol(transform) < 150))
{
gplots::heatmap.2(transform,
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Red Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
colnames(transform) <- str_remove_all(colnames(transform),"La_")
VertexSize <- apply(transform,2,mean)
VertexSize <- 5*VertexSize/max(VertexSize)
gr <- graph_from_adjacency_matrix(transform,mode = "directed",diag = FALSE,weighted=TRUE)
gr$layout <- layout_with_fr
fc <- cluster_optimal(gr)
plot(fc, gr,
edge.width = 0.5*E(gr)$weight,
vertex.size=VertexSize,
edge.arrow.size=0.5,
edge.arrow.width=0.5,
vertex.label.cex=0.65,
vertex.label.dist=1,
main="Feature Association")
}
}
#> fast | LM |
#> V644_WL V599_WL V198_NBI V497_NBI V497_WL V260_NBI
#> V3_WL V4_WL V5_WL V6_WL V7_WL V8_WL
#> 0.7462069 0.6082759 0.5172414 0.5158621 0.5365517 0.5310345
#>
#> Included: 725 , Uni p: 0.0002068966 , Base Size: 125 , Rcrit: 0.3949911
#>
#>
1 <R=1.000,thr=0.950>, Top: 69< 48 >[Fa= 69 ]( 69 , 178 , 0 ),<|>Tot Used: 247 , Added: 178 , Zero Std: 0 , Max Cor: 1.000
#>
2 <R=1.000,thr=0.950>, Top: 15< 25 >[Fa= 84 ]( 15 , 88 , 69 ),<|>Tot Used: 308 , Added: 88 , Zero Std: 0 , Max Cor: 0.999
#>
3 <R=0.999,thr=0.950>, Top: 12< 5 >[Fa= 94 ]( 10 , 40 , 84 ),<|>Tot Used: 318 , Added: 40 , Zero Std: 0 , Max Cor: 0.989
#>
4 <R=0.989,thr=0.950>, Top: 4< 2 >[Fa= 98 ]( 4 , 7 , 94 ),<|>Tot Used: 321 , Added: 7 , Zero Std: 0 , Max Cor: 0.950
#>
5 <R=0.950,thr=0.900>, Top: 92< 1 >[Fa= 147 ]( 88 , 148 , 98 ),<|>Tot Used: 469 , Added: 148 , Zero Std: 0 , Max Cor: 0.949
#>
6 <R=0.949,thr=0.900>, Top: 16< 1 >[Fa= 154 ]( 16 , 17 , 147 ),<|>Tot Used: 487 , Added: 17 , Zero Std: 0 , Max Cor: 0.907
#>
7 <R=0.907,thr=0.900>, Top: 1< 1 >[Fa= 155 ]( 1 , 1 , 154 ),<|>Tot Used: 489 , Added: 1 , Zero Std: 0 , Max Cor: 0.900
#>
8 <R=0.900,thr=0.800>, Top: 98< 1 >[Fa= 195 ]( 92 , 152 , 155 ),<|>Tot Used: 572 , Added: 152 , Zero Std: 0 , Max Cor: 0.926
#>
9 <R=0.926,thr=0.900>, Top: 1< 1 >[Fa= 196 ]( 1 , 1 , 195 ),<|>Tot Used: 573 , Added: 1 , Zero Std: 0 , Max Cor: 0.897
#>
10 <R=0.897,thr=0.800>, Top: 31< 1 >[Fa= 206 ]( 27 , 38 , 196 ),<|>Tot Used: 600 , Added: 38 , Zero Std: 0 , Max Cor: 0.894
#>
11 <R=0.894,thr=0.800>, Top: 8< 2 >[Fa= 211 ]( 7 , 11 , 206 ),<|>Tot Used: 612 , Added: 11 , Zero Std: 0 , Max Cor: 0.884
#>
12 <R=0.884,thr=0.800>, Top: 7< 1 >[Fa= 214 ]( 4 , 5 , 211 ),<|>Tot Used: 619 , Added: 5 , Zero Std: 0 , Max Cor: 0.884
#>
13 <R=0.884,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.884
#>
14 <R=0.884,thr=0.800>, Top: 4< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.881
#>
15 <R=0.881,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.868
#>
16 <R=0.868,thr=0.800>, Top: 4< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.814
#>
17 <R=0.814,thr=0.800>, Top: 1< 1 >[Fa= 214 ]( 1 , 1 , 214 ),<|>Tot Used: 619 , Added: 1 , Zero Std: 0 , Max Cor: 0.799
#>
18 <R=0.799,thr=0.800>
#>
[ 18 ], 0.7993308 Decor Dimension: 619 Nused: 619 . Cor to Base: 363 , ABase: 725 , Outcome Base: 0
#>
bootstrapping->..............................
#>
[1] 619
#> [1] 325
#> [1] 93
#> [1] 93
par(op)
if (!largeSet)
{
cormat <- cor(DEdataframe[,varlistc],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Correlation after ILAA",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
par(op)
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.9419448
if (nrow(dataframe) < 1000)
{
classes <- unique(dataframe[1:numsub,outcome])
raincolors <- rainbow(length(classes))
names(raincolors) <- classes
datasetframe.umap = umap(scale(dataframe[1:numsub,varlist]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])
}
if (nrow(dataframe) < 1000)
{
datasetframe.umap = umap(scale(DEdataframe[1:numsub,varlistc]),n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After ILAA",t='n')
text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])
}
univarRAW <- uniRankVar(varlist,
paste(outcome,"~1"),
outcome,
dataframe,
rankingTest="AUC")
100 : V102_WL 200 : V288_WL 300 : V535_WL 400 : V635_WL 500 :
V37_NBI
600 : V137_NBI 700 : V470_NBI
univarDe <- uniRankVar(varlistc,
paste(outcome,"~1"),
outcome,
DEdataframe,
rankingTest="AUC",
)
100 : La_V102_WL 200 : La_V288_WL 300 : La_V535_WL 400 : La_V635_WL
500 : V37_NBI
600 : La_V137_NBI 700 : La_V470_NBI
univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")
##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| V172_WL | 3.55e+03 | 1.78e+03 | 1046.667 | 537.2409 | 0.718095 | 0.933 |
| V220_NBI | 2.01e+02 | 1.20e+02 | 51.524 | 27.8220 | 0.747592 | 0.929 |
| V220_WL | 1.96e+02 | 1.07e+02 | 52.381 | 42.7370 | 0.097268 | 0.927 |
| V477_NBI | 6.18e-02 | 2.98e-02 | 0.149 | 0.1717 | 0.000358 | 0.925 |
| V169_NBI | 1.26e+03 | 8.24e+02 | 346.619 | 198.5476 | 0.350000 | 0.920 |
| V196_NBI | 4.52e+02 | 2.51e+02 | 134.238 | 66.3226 | 0.410564 | 0.920 |
| V182_NBI | 3.44e+02 | 2.17e+02 | 95.190 | 48.8412 | 0.793090 | 0.915 |
| V470_NBI | 3.79e-01 | 1.34e-01 | 0.188 | 0.0682 | 0.948083 | 0.913 |
| V182_WL | 3.17e+02 | 1.69e+02 | 96.476 | 87.3691 | 0.142781 | 0.912 |
| V474_NBI | 3.40e+00 | 3.13e-01 | 2.680 | 0.5481 | 0.222068 | 0.912 |
topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]
pander::pander(finalTable)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| V474_NBI | 3.40e+00 | 3.13e-01 | 2.68e+00 | 5.48e-01 | 0.2221 | 0.912 |
| V492_NBI | 4.74e-01 | 1.31e-01 | 2.68e-01 | 8.02e-02 | 0.6487 | 0.908 |
| V169_WL | 1.20e+03 | 6.66e+02 | 4.03e+02 | 4.20e+02 | 0.0543 | 0.897 |
| V474_WL | 3.19e+00 | 4.57e-01 | 2.36e+00 | 5.29e-01 | 0.9972 | 0.882 |
| V499_NBI | 7.46e-02 | 2.83e-02 | 1.34e-01 | 4.82e-02 | 0.8421 | 0.873 |
| La_V69_WL | 1.03e-03 | 1.66e-03 | -1.02e-03 | 1.56e-03 | 0.3074 | 0.872 |
| V473_NBI | 1.22e-01 | 4.19e-02 | 2.12e-01 | 1.67e-01 | 0.0188 | 0.865 |
| V481_WL | 3.63e-01 | 1.18e-01 | 2.20e-01 | 1.27e-01 | 0.1630 | 0.864 |
| V499_WL | 1.04e-01 | 4.95e-02 | 1.99e-01 | 8.56e-02 | 0.6162 | 0.858 |
| V485_WL | 3.14e+00 | 4.63e-01 | 2.44e+00 | 4.51e-01 | 0.5556 | 0.853 |
| La_V200_NBI | -1.08e+03 | 2.09e+03 | 1.03e+03 | 2.22e+03 | 0.0393 | 0.835 |
| La_V500_WL | 9.13e-01 | 2.66e-02 | 9.49e-01 | 2.80e-02 | 0.8294 | 0.833 |
| La_V27_NBI | 9.48e-04 | 5.84e-04 | 1.73e-03 | 5.82e-04 | 0.9547 | 0.831 |
| La_V296_NBI | -3.21e+02 | 1.47e+03 | 3.76e+02 | 9.94e+02 | 0.0346 | 0.810 |
dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")
pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
| mean | total | fraction |
|---|---|---|
| 2.36 | 524 | 0.718 |
theCharformulas <- attr(dc,"LatentCharFormulas")
finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])
orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]
Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores")
finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
| DecorFormula | caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | RAWAUC | fscores | |
|---|---|---|---|---|---|---|---|---|---|
| V172_WL | NA | 3.55e+03 | 1.78e+03 | 1.05e+03 | 5.37e+02 | 0.718095 | 0.933 | 0.933 | NA |
| V220_NBI | NA | 2.01e+02 | 1.20e+02 | 5.15e+01 | 2.78e+01 | 0.747592 | 0.929 | 0.929 | NA |
| V220_WL | NA | 1.96e+02 | 1.07e+02 | 5.24e+01 | 4.27e+01 | 0.097268 | 0.927 | 0.927 | NA |
| V477_NBI | NA | 6.18e-02 | 2.98e-02 | 1.49e-01 | 1.72e-01 | 0.000358 | 0.925 | 0.925 | NA |
| V169_NBI | NA | 1.26e+03 | 8.24e+02 | 3.47e+02 | 1.99e+02 | 0.350000 | 0.920 | 0.920 | NA |
| V196_NBI | NA | 4.52e+02 | 2.51e+02 | 1.34e+02 | 6.63e+01 | 0.410564 | 0.920 | 0.920 | NA |
| V182_NBI | NA | 3.44e+02 | 2.17e+02 | 9.52e+01 | 4.88e+01 | 0.793090 | 0.915 | 0.915 | NA |
| V470_NBI | NA | 3.79e-01 | 1.34e-01 | 1.88e-01 | 6.82e-02 | 0.948083 | 0.913 | 0.913 | NA |
| V474_NBI | NA | 3.40e+00 | 3.13e-01 | 2.68e+00 | 5.48e-01 | 0.222068 | 0.912 | 0.912 | NA |
| V182_WL | NA | 3.17e+02 | 1.69e+02 | 9.65e+01 | 8.74e+01 | 0.142781 | 0.912 | 0.912 | NA |
| V474_NBI1 | NA | 3.40e+00 | 3.13e-01 | 2.68e+00 | 5.48e-01 | 0.222068 | 0.912 | NA | NA |
| V492_NBI | NA | 4.74e-01 | 1.31e-01 | 2.68e-01 | 8.02e-02 | 0.648736 | 0.908 | 0.908 | 2 |
| V169_WL | NA | 1.20e+03 | 6.66e+02 | 4.03e+02 | 4.20e+02 | 0.054330 | 0.897 | 0.897 | 5 |
| V474_WL | NA | 3.19e+00 | 4.57e-01 | 2.36e+00 | 5.29e-01 | 0.997159 | 0.882 | 0.882 | NA |
| V499_NBI | NA | 7.46e-02 | 2.83e-02 | 1.34e-01 | 4.82e-02 | 0.842141 | 0.873 | 0.873 | 1 |
| La_V69_WL | - (1.863)V47_WL + V69_WL | 1.03e-03 | 1.66e-03 | -1.02e-03 | 1.56e-03 | 0.307376 | 0.872 | 0.617 | 0 |
| V473_NBI | NA | 1.22e-01 | 4.19e-02 | 2.12e-01 | 1.67e-01 | 0.018789 | 0.865 | 0.865 | 2 |
| V481_WL | NA | 3.63e-01 | 1.18e-01 | 2.20e-01 | 1.27e-01 | 0.163035 | 0.864 | 0.864 | 3 |
| V499_WL | NA | 1.04e-01 | 4.95e-02 | 1.99e-01 | 8.56e-02 | 0.616245 | 0.858 | 0.858 | 5 |
| V485_WL | NA | 3.14e+00 | 4.63e-01 | 2.44e+00 | 4.51e-01 | 0.555561 | 0.853 | 0.853 | 1 |
| La_V200_NBI | - (0.862)V184_NBI + V200_NBI | -1.08e+03 | 2.09e+03 | 1.03e+03 | 2.22e+03 | 0.039308 | 0.835 | 0.763 | -1 |
| La_V500_WL | + (0.127)V497_WL + V500_WL | 9.13e-01 | 2.66e-02 | 9.49e-01 | 2.80e-02 | 0.829410 | 0.833 | 0.797 | 1 |
| La_V27_NBI | + V27_NBI - (0.464)V49_NBI | 9.48e-04 | 5.84e-04 | 1.73e-03 | 5.82e-04 | 0.954721 | 0.831 | 0.588 | -1 |
| La_V296_NBI | - (13.104)V198_NBI + V296_NBI | -3.21e+02 | 1.47e+03 | 3.76e+02 | 9.94e+02 | 0.034643 | 0.810 | 0.758 | 0 |
featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE) #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous])
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)
#pander::pander(pc$rotation)
PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])
gplots::heatmap.2(abs(PCACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "PCA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
EFAdataframe <- dataframeScaled
if (length(iscontinous) < 2000)
{
topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)/2)
if (topred < 2) topred <- 2
uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE) # EFA analysis
predEFA <- predict(uls,dataframeScaled[,iscontinous])
EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous])
EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
gplots::heatmap.2(abs(EFACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "EFA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
}
par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(rawmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
}
pander::pander(table(dataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 17 | 4 |
| 1 | 3 | 52 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.908 | 0.819 | 0.962 |
| 3 | se | 0.945 | 0.849 | 0.989 |
| 4 | sp | 0.810 | 0.581 | 0.946 |
| 6 | diag.or | 73.667 | 14.963 | 362.674 |
par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe,control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(IDeAmodel,main="ILAA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(IDeAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
}
pander::pander(table(DEdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 17 | 4 |
| 1 | 0 | 55 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.947 | 0.871 | 0.985 |
| 3 | se | 1.000 | 0.935 | 1.000 |
| 4 | sp | 0.810 | 0.581 | 0.946 |
| 6 | diag.or | Inf | NA | Inf |
par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(PCAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}
pander::pander(table(PCAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 15 | 6 |
| 1 | 2 | 53 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.895 | 0.803 | 0.953 |
| 3 | se | 0.964 | 0.875 | 0.996 |
| 4 | sp | 0.714 | 0.478 | 0.887 |
| 6 | diag.or | 66.250 | 12.104 | 362.601 |
par(op)
EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(EFAmodel,EFAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(EFAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
}
pander::pander(table(EFAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 16 | 5 |
| 1 | 1 | 54 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.921 | 0.836 | 0.970 |
| 3 | se | 0.982 | 0.903 | 1.000 |
| 4 | sp | 0.762 | 0.528 | 0.918 |
| 6 | diag.or | 172.800 | 18.799 | 1588.369 |
par(op)